import pymysql
import random
from datetime import datetime

connect_info = {
    'host': '192.168.2.121',
    'port': 3306,
    'user': 'kettle',
    'password': 'kettle',
    'database': 'saas_shydnew1119',
    'cursorclass': pymysql.cursors.DictCursor
}
connect = pymysql.connect(**connect_info)
cursor = connect.cursor()
num = 0
# 紧急告警数
sql00 = 'select max(sn) as sn from alarm_group'
cursor.execute(sql00)
result00 = cursor.fetchall()
sn = result00[0]['sn']
alarm_list = [1, 2, 3, 4]
status_code_list = [1, 2, 3]
alarm_dist = {1: '警告', 2: '次要', 3: '重要', 4: '紧急'}
today = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
while num < 40:
    sn += 1
    source_level_code = random.choice(alarm_list)
    source_level_value = alarm_dist[source_level_code]
    status_code = random.choice(status_code_list)
    sql01 = f"""
    INSERT INTO alarm_group(sn, name, type_code, type_name, source_level_code, source_level_value, current_level_code, 
    current_level_value, event_count, total_notice_count, cur_level_notice_count, first_event_sn, first_event_time, 
    first_event_content, last_event_sn, last_event_time, status_code, status_value, recover_status, recover_status_value, 
    confirm_time, confirm_person, confirm_reason, close_time, close_person, close_reason, notice_rule_sn, event_template, 
    adder, add_time, updater, update_time, event_category_sn, effective_start_time, effective_stop_time) 
    VALUES ({sn}, '短时间内高频金库审批操作审计(重点审计)', 'sensitive-data', '敏感数据', {source_level_code}, 
    '{source_level_value}', {source_level_code}, '{source_level_value}', 207499, 0, 0, 
    12409201721230004, '{today}', '账号：短时间内给多个账号审批，符合短时间内高频金库审批操作审计', 
    12409201727094003, '{today}', {status_code}, '待确认', null, null, '1970-01-01 00:00:00', '', '', '1970-01-01 00:00:00', 
    '', '', 0, '短时间内高频金库审批操作审计(重点审计)', 'wujia', '{today}', 'wujia', '{today}', 
    40510006, null, null)
    """
    cursor.execute(sql01)
    connect.commit()
    num += 1
